package ps.net;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;





public class ChatContent implements PacketContent {
    
    public static final String TO_ALL_PS_CLIENTS = "";
    
    String sender;
    String reciever;
    String msg;
    
    ChatContent() {
        this("<unbekannt>", TO_ALL_PS_CLIENTS, "");
    }
    
    public ChatContent(String sender, String reciever, String msg) {
        this.sender = sender;
        this.reciever = reciever;
        this.msg = msg;
    }
    
    @Override
    public void writeContent(OutputStream out) throws IOException {
        // write sender
        Packet.writeString(out, sender);
        // write reciever
        Packet.writeString(out, reciever);
        // write msg
        Packet.writeString(out, msg);
    }
    
    @Override
    public void readContent(InputStream in) throws IOException {
        // read sender
        sender = Packet.readString(in);
        // read reciever
        reciever = Packet.readString(in);
        // read msg
        msg = Packet.readString(in);
    }
    
    @Override
    public String toString() {
        String ret = "[ Message |";
        ret += " sender=\"" + sender + "\"";
        ret += " reciever=\"" + reciever + "\"";
        ret += " msg=\"" + msg + "\"";
        ret += " ]";
        return ret;
    }
    
    public void setSender(String sender) {
        this.sender = sender;
    }
    
    public String getSender() {
        return sender;
    }
    
    public String getReciever() {
        return reciever;
    }
    
    public String getMsg() {
        return msg;
    }
    
}
